--[[
直线波伤害
]]

local mt = ac.skill['震荡波']
mt.art = [[ReplaceableTextures\CommandButtons\BTNMarkOfFire.blp]]
mt.targettype = "点"
mt.range = 800
mt.cool = 6
mt.damage = 100         --造成伤害
mt.damage_type = '魔法' --伤害类型
mt.damage_time = 0.1    --伤害计算频率，防止卡顿可以改高
mt.damage_area = 120    --伤害宽度
mt.distance = 900       --波长度
--投射物模型
mt.missile_art = [[Abilities\Spells\Orc\Shockwave\ShockwaveMissile.mdl]]
mt.missile_speed = 900   --投射物速度
mt.missile_height = 0
mt.missile_accel = 0
mt.missile_size = 1

function mt:on_cast_shot()
    local hero = self.owner
    local target = self.target
    local angle = hero:get_point()/target:get_point()
    self:shot_missile(angle)
end

function mt:shot_missile(angle,group,start)
    local hero = self.owner
    local start = start or hero:get_point()
    local damage_time = ac.clock() + self.damage_time
    local last_point = start:copy()
    self.group = group or {}
    ac.mover('line'){
        start = start,
        angle = angle,
        model = self.missile_art,
        size = self.missile_size,
        speed = self.missile_speed,
        height = self.missile_height,
        accel = self.missile_accel,
        distance = self.distance,
        on_move = function(_,point)
            if self.damage>0 then
                if ac.clock() - damage_time<self.damage_time then
                    return
                end
                local len = last_point * point
                damage_time = damage_time + self.damage_time
                for u in ac.selector('unit')
                    : line(last_point,angle,len,self.damage_area)
                    : enemy(hero)
                    : loop()
                do
                    if not self.group[u] then
                        self.group[u] = true
                        u:damage{
                            source = hero,
                            damage_type = self.damage_type,
                            damage = self.damage,
                            skill = self,
                        }
                    end
                end
            end
        end,
        on_remove = function(mover)
            self:notify('on_finish',mover)
        end
    }
end

